<template>
    <tbody>
         <tr >
           <td> <input type="checkbox" v-model="item.checked"></td>
             <td>{{item.name}}</td>
            <td>{{item.price}}</td>
             <td>
              <button @click="btn(-1)">-</button><span>{{item.num}}</span><button  @click="btn(1)" >+</button>
             </td>
             <td>{{item.price * item.num}}</td>
             <td>
              <button @click="del(index)">删除</button>
             </td>
         </tr>
      </tbody>
     
</template>

<script>
import {mutations } from 'vuex'
export default {
       props:{
      item:Object,
      index:Number
    },
    methods:{
      // ...mutations(['changeNum']),
      btn(num){
       
        const newNum = this.item.num + num
         if(newNum<0) return
        // console.log(this.item.num + num);
        this.$store.commit('changeNum',{
          num:newNum,
          index:this.index
        })
      },
      del(index){
        this.$store.commit('delList',{
          index
        })
      }
    }
}
</script>

<style>

</style>